package com.yunbao.project.basedata.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yunbao.core.respones.Result;
import com.yunbao.core.respones.ResultBuilder;
import com.yunbao.core.respones.ResultEnum;
import com.yunbao.project.basedata.entity.GoodsUnit;
import com.yunbao.project.basedata.entity.Storage;
import com.yunbao.project.basedata.query.GoodsUnitQuery;
import com.yunbao.project.basedata.query.StorageQuery;
import com.yunbao.project.basedata.service.IGoodsUnitService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 * 商品单位前端控制器
 * </p>
 *
 * @author 安能
 * @since 2019-09-19
 */
@RestController
@RequestMapping("goodsUnit")
public class GoodsUnitController {

    @Resource
    IGoodsUnitService goodsUnitService;


    /**
     * 增加商品单位
     *
     * @param goodsUnit {@link Storage }
     * @return Result
     */
    @PostMapping("insert")
    public Result insert(@RequestBody GoodsUnit goodsUnit) {

        goodsUnitService.save(goodsUnit);
        return ResultBuilder.success(ResultEnum.ADD_SUCCESS);
    }

    /**
     * 根据id删除仓库
     *
     * @param id id
     * @return Result
     */
    @PostMapping("deleteById")
    public Result deleteById(Integer id) {

        goodsUnitService.removeById(id);
        return ResultBuilder.success(ResultEnum.DELETE_SUCCESS);
    }

    /**
     * 根据id修改仓库
     *
     * @param goodsUnit storage
     * @return Result
     */
    @PostMapping("updateById")
    public Result updateById(@RequestBody GoodsUnit goodsUnit) {

        goodsUnitService.updateById(goodsUnit);
        return ResultBuilder.success(ResultEnum.UPDATA_SUCCESS);
    }

    /**
     * 获取商品单位列表查询
     *
     * @param goodsUnitQuery {@link StorageQuery 编号,姓名,联系人,电话 }
     * @return 仓库列表
     */
    @PostMapping("getList")
    public Result getLists(@RequestBody GoodsUnitQuery goodsUnitQuery) {
        IPage<GoodsUnit> page = goodsUnitService.page(new Page<>(
                        goodsUnitQuery.getCurrent(),
                        goodsUnitQuery.getSize()
                )
        );
        return ResultBuilder.success(page);
    }
}
